package com.dkha.server.controllers;

import com.dkha.common.modules.vo.search.SearchRequestVo;
import com.dkha.common.result.CommonResult;
import com.dkha.common.systemcode.SystemCode;
import com.dkha.common.util.UtilValidate;
import com.dkha.server.services.IFaceLibraryService;
import com.dkha.server.services.IFileService;
import com.dkha.server.services.IPortraitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author Spring
 * @Since 2019/12/9 15:32
 * @Description 人脸检索controller
 */
@RestController
@RequestMapping(value = "/search")
@Api(tags = "检索")
@Slf4j
public class SearchController extends CommonResult {

    @Autowired
    private IFaceLibraryService faceLibraryService;
    @Autowired
    private IPortraitService portraitService;

    @GetMapping(value = "/libraries")
    @ApiOperation(value = "获取所有的库")
    public CommonResult findFaceLibraries() {
        return successResult(faceLibraryService.findFaceLibraries());
    }


    @PostMapping(value = "/search")
    @ApiOperation(value = "检索功能")
    public CommonResult search(
            @ApiParam(required = true, name = "searchRequestVo", value = "{\n" +
                    "\t\"libIdList\": [\"要检索的人像库Id集合\"],\n" +
                    "\t\"faceImageRequestList\": [\"需要检索的图片上传后的url地址，注意，只能有一个url地址，此处参数做成集合形式，是为了兼容后续修改\"],\n" +
                    "\t\"faceApiResultMap\": {\n" +
                    "\t\t\"后台传输回来，请求的时候，请再次传输到后台\": 0.0\n" +
                    "\t},\n" +
                    "\n" +
                    "\t\"minScore\": \"搜索阀值\",\n" +
                    "\t\"pageParam\": {\n" +
                    "\t\t\"pageNo\": 1,\n" +
                    "\t\t\"pageSize\": 10,\n" +
                    "\t\t\"note\": {\n" +
                    "\t\t\t\"search\": \"姓名/身份证号码\",\n" +
                    "\t\t\t\"sex\": \"性别 0男 1女\"\n" +
                    "\t\t},\n" +
                    "\t\t\"sort\": {},\n" +
                    "\t\t\"sortString\": \"\"\n" +
                    "\t}\n" +
                    "}")
            @RequestBody SearchRequestVo searchRequestVo) {
        return successResult(portraitService.libSearchPage(searchRequestVo));
    }
}
